package com.lrs.s2sh.web.action;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.RequestAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.lrs.s2sh.model.Person;
import com.lrs.s2sh.model.State;
import com.lrs.s2sh.service.PersonService;
import com.opensymphony.xwork2.ActionSupport;

@Controller("personAction")
@Scope("prototype")
//@Namespace("/person")
//@ParentPackage("basicstruts2")
//@Results( { @Result(name = "success", location = "/index.jsp") } )
public class PersonAction extends ActionSupport implements RequestAware {
	
	private static final long serialVersionUID = 1L;
	
	private Map<String, Object> request;
	private PersonService personService ;
	
	private Person personBean;
	
	private String [] sports = {"football", "baseball", "basketball" };
	
	private String [] genders = {"male", "female", "not sure" };
	
	private List<State> states ;

	private String [] carModelsAvailable = {"Ford","Chrysler","Toyota","Nissan"};

//	@Resource
	@Autowired
	public void setPersonService(PersonService personService) {
		this.personService = personService;
	}

	public String execute() throws Exception {
		
		personService.save(getPersonBean());
		
		return SUCCESS;
		
	}
	
	public String input() throws Exception {
		
		setPersonBean( personService.get(1L) );
		
		return INPUT;
	}
	
	public Person getPersonBean() {
		
		
		return personBean;
		
	}
	
	public void setPersonBean(Person person) {
		personBean = person;
		
	}

	public List<String> getSports() {
		return Arrays.asList(sports);
	}
	
	public List<String> getGenders() {
		
		return Arrays.asList(genders);
		
	}

	public List<State> getStates() {
		
		
		states = new ArrayList<State>();
		states.add( new State("AZ", "Arizona") );
		states.add( new State("CA", "California") );
		states.add( new State("FL", "Florida") );
		states.add( new State("KS", "Kansas") );
		states.add( new State("NY", "New York") );
		
		return states;
	}

	public String [] getCarModelsAvailable() {
		return carModelsAvailable;
	}

	@Override
	public void setRequest(Map<String, Object> request) {
		this.request = request;
	}

}
